import numpy as np

Q = 15  # Battery capacity in GW
C = 15 / 4  # Maximum charge/discharge rate in GW
a = 0.1  # Coefficient for linear term in quadratic cost function in $10^6/GW
b = 0.005  # Coefficient for quadratic term in quadratic cost function in $10^6/GW^2

l = np.asarray(
    [21.34191954, 21.18082759, 20.96743678, 20.76724138, 20.60328736,
     20.47901149, 20.33221839, 20.20188506, 20.1091954, 20.06005747,
     19.98218391, 19.91656322, 19.91108046, 19.92598851, 19.9263908,
     19.95235632, 20.07229885, 20.25916092, 20.40158621, 20.57654023,
     20.91581609, 21.30312644, 21.59070115, 21.91572414, 22.44517241,
     22.96125287, 23.23689655, 23.47072414, 23.7072069, 23.9123908,
     23.9323908, 23.89454023, 23.84212644, 23.7435977, 23.47114943,
     23.17532184, 22.94258621, 22.71243678, 22.38668966, 22.08251724,
     21.80866667, 21.53998851, 21.2727931, 21.03797701, 20.8167931,
     20.62733333, 20.46255172, 20.29644828, 20.13751724, 20.0298046,
     19.91989655, 19.83633333, 19.75285057, 19.72950575, 19.70543678,
     19.72454023, 19.72749425, 19.75965517, 19.81554023, 19.93401149,
     20.05833333, 20.22910345, 20.43187356, 20.68208046, 20.89424138,
     21.20185057, 21.58913793, 22.02983908, 22.41070115, 22.85716092,
     23.38570115, 23.94273563, 24.44466667, 24.87712644, 25.19521839,
     25.44010345, 25.65931034, 25.90294253, 26.06342529, 26.07808046,
     25.96606897, 25.814, 25.63070115, 25.41873563, 25.21206897,
     25.02482759, 24.75267816, 24.44406897, 24.0662069, 23.6843908,
     23.31312644, 22.94794253, 22.58410345, 22.2401954, 21.91117241,
     21.60796552])

s = np.asarray(
    [-0.03617241, -0.03613793, -0.03657471, -0.03378161, -0.03536782,
     -0.03536782, -0.03535632, -0.03531034, -0.03547126, -0.03557471,
     -0.03565517, -0.03601149, -0.03644828, -0.03697701, -0.03742529,
     -0.03809195, -0.03837931, -0.03843678, -0.03847126, -0.03865517,
     -0.03906897, -0.03950575, -0.03977011, -0.03964368, -0.03295402,
        0.03156322,  0.24817241,  0.68012644,  1.34516092,  2.34498851,
        3.58345977,  4.82156322,  6.09688506,  7.20993103,  8.09786207,
        8.61782759,  9.16962069,  9.63973563,  9.79171264,  9.92125287,
     10.1645977, 10.23402299, 10.20718391, 10.16213793, 10.15095402,
     10.08826437, 10.09511494, 10.00224138,  9.96237931,  9.94972414,
        9.90524138,  9.85172414,  9.79181609,  9.75329885,  9.64002299,
        9.5753908,  9.47358621,  9.32724138,  9.27497701,  9.19827586,
        9.04288506,  8.85916092,  8.64457471,  8.42649425,  7.93597701,
        7.36075862,  6.97835632,  6.30435632,  5.39842529,  4.571,
        3.81128736,  2.97521839,  2.09649425,  1.31252874,  0.66016092,
        0.23991954,  0.04734483, -0.02125287, -0.03608046, -0.03522989,
     -0.03489655, -0.03495402, -0.03574713, -0.03547126, -0.03489655,
     -0.03428736, -0.03433333, -0.03434483, -0.03445977, -0.03554023,
     -0.03548276, -0.03541379, -0.0356092, -0.03498851, -0.03567816,
     -0.03563218])

n = l - s
""""
# Below is the code to generate data from its source CAISO
# You will need to install the CAISO package to run this code
# pip install gridstatus
import gridstatus
import pandas as pd
start = pd.Timestamp("March 1, 2021").normalize()
end = pd.Timestamp("March 31, 2021").normalize()
load_data = caiso.get_load(start, end=end)
load_data_15_minute = load_data.set_index("Time").resample("15T").mean()
load = load_data_15_minute.groupby(load_data_15_minute.index.time).mean()
fuel_mixture_data = caiso.get_fuel_mix(start, end=end, verbose=False)
fuel_mixture_data_15_minute = fuel_mixture_data .set_index("Time").resample("15T").mean()
solar = fuel_mixture_data_15_minute.groupby(fuel_mixture_data_15_minute.index.time).mean()
# Combine load and solar into a single dataframe
combined_df = pd.DataFrame({'Load': load['Load'],'Solar': solar['Solar']})
combined_df['Net_load'] = combined_df['Load'] - combined_df['Solar']
# Convert to numpy arrays and adjust for GW
l = combined_df['Load'].to_numpy()*0.001
n = combined_df['Net_load'].to_numpy()*0.001
s = combined_df['Solar'].to_numpy()*0.001
"""
